package cn.dinxian.activiti.demo2.service.impl;

import cn.dinxian.activiti.demo2.service.MyTaskUtil;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import cn.dinxian.entity.ActTaskDTO;
import java.util.List;
import java.util.stream.Collectors;
import org.activiti.engine.task.Task;
import org.assertj.core.util.Lists;
import org.springframework.stereotype.Service;

/**
 * @author dingxian
 * @Title:
 * @param:
 * @return:
 * @Date 2023/3/2 19:21
 * @Description:
 */
@Service
public class MyTaskUtilImpl implements MyTaskUtil {


  public List<ActTaskDTO> assembleTask(List<Task> tasks) {
    if (ObjectUtils.isEmpty(tasks)) {
      return Lists.emptyList();
    }
    return tasks.stream().map(this::assembleTask).collect(Collectors.toList());
  }

  public ActTaskDTO assembleTask(Task task) {

    return ActTaskDTO.builder()
        .taskId(task.getId())
        .taskName(task.getName())
        .description(task.getDescription())
        .priority(task.getPriority())
        .owner(task.getOwner())
        .assignee(task.getAssignee())
        .processInstanceId(task.getProcessInstanceId())
        .executionId(task.getExecutionId())
        .processDefinitionId(task.getProcessDefinitionId())
        .createTime(task.getCreateTime())
        .taskDefinitionKey(task.getTaskDefinitionKey())
        .dueDate(task.getDueDate())
        .category(task.getCategory())
        .parentTaskId(task.getParentTaskId())
        .tenantId(task.getTenantId())
        .formKey(task.getFormKey())
        .taskLocalVariables(task.getTaskLocalVariables())
        .processVariables(task.getProcessVariables())
        .claimTime(task.getClaimTime())
        .businessKey(task.getBusinessKey())
        .status(task.isSuspended()?"暂停":"活动")
        .build();
  }


}
